﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

using AimGameLibrary.GameObject;

namespace AimGameLibrary
{
    public class Identification
    {

        [XmlElementAttribute("Boolean", typeof(Boolean))]
        [XmlElementAttribute("int", typeof(int))]
        [XmlElementAttribute("Double", typeof(Double))]
        [XmlElementAttribute("float", typeof(float))]
        [XmlElementAttribute("Vector2", typeof(Vector2))]
        [XmlElementAttribute("Rectangle", typeof(Rectangle))]
        [XmlElementAttribute("String", typeof(String))]
        [XmlElementAttribute("Color", typeof(Color))]
        [XmlElementAttribute("SpriteEffects", typeof(SpriteEffects))]
        [XmlElementAttribute("NodeInputMode", typeof(NodeInputMode))]
        [XmlElementAttribute("NodeData", typeof(NodeData))]
        [XmlElementAttribute("FrameData", typeof(FrameData))]
        [XmlElementAttribute("KeyFrameData", typeof(KeyFrameData))]
        [XmlElementAttribute("ViewData", typeof(ViewData))]
        [XmlElementAttribute("Keys", typeof(Keys))]
        [XmlElementAttribute("Buttons", typeof(Buttons))]

        [XmlElementAttribute("Position", typeof(Point))]
        [XmlElementAttribute("StateGroup", typeof(StateGroup))]
        public object[] Items;
    }

    public class XMLData<T>
    {
        public T Load(String fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            T tempData;
            FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
            XmlReader reader = new XmlTextReader(fs);
            tempData = (T)serializer.Deserialize(reader);
            fs.Close();
            return tempData;
        }

        public void Save(T item, String fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            TextWriter writer = new StreamWriter(fileName);

            serializer.Serialize(writer, item);
            writer.Close();
        }
    }
}
